package com.turing.usdtpay.mvp.view.popwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.adapter.UserAdapter;
import com.turing.usdtpay.entity.UserData;
import com.turing.usdtpay.manager.UserManager;

import java.util.ArrayList;

/**
 * @作者：JAY
 * @创建时间：2019/10/24 11:30
 * @描述：
 **/
public class UserPopWindow extends CommonPopupWindow{

    private ListView listView;
    private OnClickListener listener;
    private ArrayList<UserData> accountList;

    public UserPopWindow(Context context, int layoutRes, int width, int height,ArrayList<UserData> accountList) {
        super(context, layoutRes, width, height);
        this.accountList = accountList;
        setUiBeforShow();
    }

    private void setUiBeforShow() {
        UserAdapter adapter = new UserAdapter(mContext,accountList);
        adapter.setOnClickListener(new UserAdapter.OnClickListener() {
            @Override
            public void onClick() {
                dismiss();
            }
        });
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                listener.onItemClick(accountList.get(position).getAccount(),accountList.get(position).getPwd());
            }
        });
    }

    @Override
    protected void initView() {
        listView = (ListView) mContentView.findViewById(R.id.list);
    }

    public void setItemOnClickListener(OnClickListener listener) {
        this.listener = listener;
    }

    public interface OnClickListener{
        public void onItemClick(String account,String pwd);
    }

    public void dismiss(){mInstance.dismiss();}

    public void showAsDropDown(View anchor) {
        mInstance.showAsDropDown(anchor);
    }

}
